<template>
  <div class="app-container">
    <el-row :gutter="20">
      <!--用户数据-->
      <el-col :span="24" :xs="24">
        <el-form :model="queryParams" ref="queryForm" :inline="true" v-show="showSearch" label-width="68px">
          <el-form-item label="姓名" prop="empName">
            <el-input
              v-model="queryParams.empName"
              placeholder="请输入姓名"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="工号" prop="userName">
            <el-input
              v-model="queryParams.userName"
              placeholder="请输入工号"
              clearable
              size="small"
              style="width: 240px"
              @keyup.enter.native="handleQuery"/>
          </el-form-item>
          <el-form-item label="状态" prop="status">
            <el-select
              v-model="queryParams.status"
              placeholder="用户状态"
              clearable
              size="small"
              style="width: 240px">
              <el-option
                v-for="dict in dict.type.sys_normal_disable"
                :key="dict.value"
                :label="dict.label"
                :value="dict.value"/>
            </el-select>
          </el-form-item>
          <el-form-item label="创建时间">
            <el-date-picker
              v-model="dateRange"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>

        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['system:user:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAddlist"
              v-hasPermi="['system:user:add']"
            >批量新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['system:user:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['system:user:remove']"
            >删除</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="info"
              plain
              icon="el-icon-upload2"
              size="mini"
              @click="handleImport"
              v-hasPermi="['system:user:import']"
            >导入</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="warning"
              plain
              icon="el-icon-download"
              size="mini"
              :loading="exportLoading"
              @click="handleExport"
              v-hasPermi="['system:user:export']"
            >导出</el-button>
          </el-col>
          <right-toolbar :showSearch.sync="showSearch" @queryTable="getList" :columns="columns"></right-toolbar>
        </el-row>

        <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
          <el-table-column type="selection" width="50" align="center" />
          <el-table-column label="工号" align="center" key="userName" prop="userName"  v-if="columns[0].visible" />
          <el-table-column label="姓名" align="center" key="empName" prop="empName" v-if="columns[1].visible" :show-overflow-tooltip="true"/>
          <el-table-column :show-overflow-tooltip="true" label="部门" align="center" key="unitLabel" prop="unitLabel" v-if="columns[2].visible"  />
          <el-table-column label="角色" align="center" key="role.roleName" prop="role.roleName" v-if="columns[3].visible" :show-overflow-tooltip="true"   />
          <el-table-column label="状态" align="center" key="status" v-if="columns[4].visible">
            <template slot-scope="scope">
              <el-switch
                v-model="scope.row.status"
                active-value="0"
                inactive-value="1"
                @change="handleStatusChange(scope.row)"
              ></el-switch>
            </template>
          </el-table-column>
          <!-- 转化时间格式封装函数：parseTime 在util/index.js中 -->
          <el-table-column label="创建时间" align="center" prop="createTime" v-if="columns[5].visible" sortable>
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.createTime) }}</span>
            </template>
          </el-table-column>
          <el-table-column
            label="操作"
            align="center"
            class-name="small-padding fixed-width"
          >
            <template slot-scope="scope" v-if="scope.row.userId !== 1" >
              <el-button
              id="userIdJuri"
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['system:user:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['system:user:remove']"
              >删除</el-button>
              <el-dropdown size="mini" @command="(command) => handleCommand(command, scope.row)" v-hasPermi="['system:user:resetPwd', 'system:user:edit']">
                <span class="el-dropdown-link">
                  <i class="el-icon-d-arrow-right el-icon--right"></i>更多
                </span>
                <el-dropdown-menu slot="dropdown">
                  <el-dropdown-item command="handleResetPwd" icon="el-icon-key"
                    v-hasPermi ="['system:user:resetPwd']">重置密码</el-dropdown-item>
                  <el-dropdown-item command="handleAuthRole" icon="el-icon-circle-check"
                    v-hasPermi ="['system:user:edit']">分配角色</el-dropdown-item>
                </el-dropdown-menu>
              </el-dropdown>
            </template>
          </el-table-column>
        </el-table>

        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList"/>
      </el-col>
    </el-row>

    <!-- 添加或修改参数配置对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="10">
            <el-form-item label="工号" prop="userName">
              <el-input id="userIdInput" v-model="form.userName" :style="{ message }" placeholder="请输入工号" maxlength="11" />
            </el-form-item>
          </el-col>
          <el-col :span="2" align="center">
              <el-button type="primary" @click="handVerfi" :style="{ display: visibleLine }" >验证</el-button>
            </el-col>
          <el-col :span="10">
            <el-form-item label="姓名" prop="empName" :style="{ margin: running }" >
              <el-input v-model="form.empName"  placeholder="请获取用户姓名" readonly style="width: 154px" />
            </el-form-item>
          </el-col>

        </el-row>
        <el-row>
          <el-col :span="10">
            <el-form-item label="部门" prop="unitLabel">
              <el-input  v-model="form.unitLabel" placeholder="请获取用户部门" readonly  />
            </el-form-item>
          </el-col>

          <el-col :span="12">
            <el-form-item label="职级" prop="title" style="margin-left: 46px">
              <el-input v-model="form.title" placeholder="请获取用户职级" readonly />
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
        </el-row>
        <el-row>

          <el-col :span="10">
            <el-form-item label="角色">
              <el-select  v-model="form.roleId" clearable  @change="hangSelectChange" placeholder="请选择">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.roleId"
                  :label="item.roleName"
                  :value="item.roleId"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>


        <el-divider content-position="center">部门权限</el-divider>
          <!--部门数据   :disable-branch-nodes="true"-->
          <el-row style="margin-top: 50px">
            <el-col :span="20">
              <el-form-item label="部门选择" prop="label">
                <treeselect
                    id="depInput"
                    v-model="form.labelIds"
                    :options="deptOptions"
                    :multiple="true"
                    placeholder="请选择或搜索部门"
                    @select="handleSelect"
                    collapse-tags:true/>
              </el-form-item>
            </el-col>

            <el-col :span="4" align="center">
              <el-button type="primary" @click="getDept">添加</el-button>
            </el-col>
          </el-row>

          <el-table v-loading="loading" :data="priviList" @selection-change="handleSelectionChange">
          <!-- <el-table-column label="编号" align="center" key="userId" prop="userId"  /> -->
          <el-table-column  label="序号" align="center">
            <template scope="scope">
              <span>{{scope.$index + 1 }}</span>
            </template>
          </el-table-column>
          <el-table-column label="部门" :show-overflow-tooltip="true" align="center"  prop="label"  />
          <el-table-column label="部门编号" align="center" key="id"  prop="id"  :show-overflow-tooltip="true" />
          <el-table-column
            label="删除"
            align="center"
            width="160"
            class-name="small-padding fixed-width">
            <template slot-scope="scope" v-if="scope.row.userId !== 1">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="Deletetable(scope.row)"
                v-hasPermi="['system:user:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>

  <!-- 批量添加 -->
    <el-dialog :title="title" :visible.sync="list" @close="handleClose" width="600px" append-to-body>
      <el-form ref="forms" :model="forms" :rules="rules" label-width="80px">
        <el-row>
          <el-col :span="20">
            <el-form-item label="工号">
              <el-input id="userIdAddlist" v-model="forms.empId" :change="check_num()" type="textarea" placeholder="请输入工号"></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="4" align="center">
              <el-button type="primary"  style="padding: 20px 10px" @click="handAddlist">验证&添加</el-button>
            </el-col>
        </el-row>

        <el-row>
          <el-col :span="12">
            <el-form-item label="角色">
              <el-select v-model="forms.roleId"  placeholder="请选择">
                <el-option
                  v-for="item in roleOptions"
                  :key="item.roleId"
                  :label="item.roleName"
                  :value="item.roleId"
                  :disabled="item.status == 1"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>

          <el-table v-loading="loading" :data="Addlist"  @selection-change="handleSelectionChange">
          <el-table-column  label="编号" align="center">
            <template scope="scope">
              <span>{{scope.$index + 1}}</span>
            </template>
          </el-table-column>
          <el-table-column label="姓名" align="center" key="empName" prop="empName"  :show-overflow-tooltip="true"  />
          <el-table-column label="工号" align="center" key="empId" prop="empId"  width="120"  />
          <el-table-column label="部门名称" align="center" key="unitLabel" prop="unitLabel" :show-overflow-tooltip="true" />
          <el-table-column
            label="删除"
            align="center"
            width="160"
            class-name="small-padding fixed-width">
            <template slot-scope="scope" v-if="scope.row.userId !== 1">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="AddDelete(scope.row)"
                v-hasPermi="['system:user:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitAddForm">确 定</el-button>
        <el-button  @click="Addfalse">取 消</el-button>
      </div>
    </el-dialog>

    <!-- 用户导入对话框 -->
    <el-dialog :title="upload.title" :visible.sync="upload.open" width="400px" append-to-body>
      <el-upload
        ref="upload"
        :limit="1"
        accept=".xlsx, .xls"
        :headers="upload.headers"
        :action="upload.url + '?updateSupport=' + upload.updateSupport"
        :disabled="upload.isUploading"
        :on-progress="handleFileUploadProgress"
        :on-success="handleFileSuccess"
        :auto-upload="false"
        drag>
        <i class="el-icon-upload"></i>
        <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em></div>
        <div class="el-upload__tip text-center" slot="tip">
          <div class="el-upload__tip" slot="tip">
            <el-checkbox v-model="upload.updateSupport" /> 是否更新已经存在的用户数据
          </div>
          <span>仅允许导入xls、xlsx格式文件。</span>
          <el-link type="primary" :underline="false" style="font-size:12px;vertical-align: baseline;" @click="importTemplate">下载模板</el-link>
        </div>
      </el-upload>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitFileForm">确 定</el-button>
        <el-button @click="upload.open = false">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { listUser, getEmpById,addBatch, getUser, delUser, addUser, updateUser, exportUser, resetUserPwd, changeUserStatus, importTemplate } from "@/api/system/user";
import { getToken } from "@/utils/auth";
import { treeselect,getDeptPermissionByUser } from "@/api/system/dept";
// 导入vue-treeSelect插件
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";

export default {
  name: "User",
  // 字典 用户性别 系统开关
  dicts: ['sys_normal_disable', 'sys_user_sex'],
  components: { Treeselect },
  data() {
    return {
      labels: [],
      message: "",
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 用户表格数据
      userList: [],
      //部门权限表格数据
      priviList: [],
      // 弹出层标题
      title: "",
      // 部门树选项
      Addlist: [],
      running: "",
      datatest: [],
      empIds: "",
      //隐藏
      visibleLine: '',

      // 是否显示弹出层
      open: false,
      list: false,
      // 日期范围
      dateRange: [],
      // 职级选项
       dept: [],
      // 角色选项
      roleOptions: [],
      //部门选项
      deptOptions: [],
      userId: "",
      deptNames: undefined,
      status: "0",
      remark:"",
      // 表单参数
      form: {},
      forms: {},
      defaultProps: {
        children: "children",
        label: "label"
      },

      // 用户导入参数
      upload: {
        // 是否显示弹出层(用户导入)
        open: false,
        // 弹出层标题(用户导入)
        title: "",
        // 是否禁用上传
        isUploading: false,
        // 是否更新已经存在的用户数据
        updateSupport: 0,
        // 设置上传的请求头部
        headers: { Authorization: "Bearer " + getToken() },
        // 上传的地址
        url: process.env.VUE_APP_BASE_API + "/system/user/importData"
      },
      // 查询参数
      queryParams: {
        empName: undefined,
        userName: undefined,
        status: undefined,
        dateRange: undefined
      },
      // 列信息
      columns: [
        { key: 0, label: `工号`, visible: true },
        { key: 1, label: `姓名`, visible: true },
        { key: 2, label: `部门`, visible: true },
        { key: 3, label: `角色`, visible: true },
        { key: 4, label: `状态`, visible: true },
        { key: 5, label: `创建时间`, visible: true }
      ],
      // 表单校验
      rules: {
        // unitLabel: [
        //   { required: true, message: "用户部门不能为空", trigger: "blur" },
        // ],
        // empName: [
        //   { required: true, message: "用户姓名不能为空", trigger: "blur" }
        // ],
        userName: [
          { required: true, message:"用户工号不能为空", trigger: "blur" }
        ],
        // deptNames: [
        //   { required: true, message:"部门选择不能为空", trigger: "blur" }
        // ],
      }
    };
  },
  watch: {
    // 根据名称筛选部门树
    unitLabel(val) {
      this.$refs.tree.filter(val);
    }
  },
  created() {
    this.getList();
  },
  methods: {
    // 查询用户列表
    getList() {
      this.loading = true;
      // 查询用户列表
      listUser(this.addDateRange(this.queryParams, this.dateRange)).then(response => {
          this.userList = response.rows;
          this.total = response.total;
          this.loading = false;
        }
      );
    },

    getiViret(){
      this.priviList = [];
    },

    //查询部门权限列表
    getiviList() {
      this.loading = true;

    },
    // 初始化 默认查询部门下拉树结构
    getTreeselect() {
      // 调取treeSelect方法
      treeselect().then(response => {
        this.deptOptions = response.data;
      });
    },
    // 点击添加 树状图选择
    handleSelect(node) {
      let idData =node.id;
      let idName=node.label;
      var params={}
      params.id = idData;
      params.label = idName;
      this.datatest.push(params);
      this.key += 1;
    },

    //添加按钮操作
     getDept() {
      // 清空input
      this.form.labelIds = [];
      this.datatest.forEach(el => {
        this.priviList.push(el);
        this.dept = el.id;
      });
      this.priviList = this.getsliep();
      this.dept = this.getsliepId();
    },

    getsliep(){
      var result = [];
      var obj = {};
      for(var i =0; i<this.priviList.length; i++){
        if(!obj[this.priviList[i].id]){
          result.push(this.priviList[i]);
          obj[this.priviList[i].id] = true;
        }
      }
      return result;
    },

    getsliepId(){
      var resultId = [];
      var objId = {};
      for(var i =0; i<this.priviList.length; i++) {
        if(!objId[this.priviList[i].id]) {
          resultId.push(this.priviList[i].id);
          objId[this.priviList[i].id] = true;
        }
      }
      return resultId;
    },

    // 筛选节点
    filterNode(value, data) {
      if (!value) return true;
      return data.label.indexOf(value) !== -1;
    },
    // 节点单击事件
    handleNodeClick(data) {
        this.queryParams.deptNames = data.id;
        this.getList();
      },
    // 用户状态修改
    handleStatusChange(row) {
      console.log("用户状态修改",row)
      let text = row.status === "0" ? "启用" : "停用";
      // element中的模态框
      this.$modal.confirm('确认要"' + text + '""' + row.userName + '"用户吗？').then(function() {
         // 返回用户状态修改
        return changeUserStatus(row.userId, row.status);
      }).then(() => {
        this.$modal.msgSuccess(text + "成功");
      }).catch(function() {
        row.status = row.status === "0" ? "1" : "0";
      });
    },
    // 取消按钮
    cancel() {
      // 关闭当前按钮,重置
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        userId: "",
        userName: "",
        empName: "",
        unitLabel: "",
        title: "",
        roleId: "",
        roleName: "",
        dept: [],
        roleIds: [],
        labelIds: [],
      };
      this.resetForm("form");
    },
    //批量添加表单重置
    resets() {
      this.forms = {
        empName: "",
        empId: "",
        unitLabel: "",
        roleId:"",
        empIds:"",
        Addlist: [],
      }
      this.resetForm("forms");
    },

    // 搜索按钮操作
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    // 重置按钮操作
    resetQuery() {
      // 重置日期选择
      this.dateRange = [];
      // 清空重置
      this.resetForm("queryForm");
      // 重新调取搜索查询按钮
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log("进行多选",selection);
      this.ids = selection.map(item => item.userId);
      // 单行不能等于1的索引值,不能多选
      this.single = selection.length != 1;
      // 多选不能等于全部的长度
      this.multiple = !selection.length;
    },
    // 点击更多的按钮操作触发
    handleCommand(command, row) {
      console.log("测试111",command, row)
      switch (command) {
        case "handleResetPwd":
          this.handleResetPwd(row);
          break;
        case "handleAuthRole":
          this.handleAuthRole(row);
          break;
        default:
          break;
      }
    },
    // 新增按钮操作
    handleAdd() {
      // 重置
      this.reset();
      // 清空弹出窗体中的Table中的data
      this.getiViret();// 清空弹出窗体中的Table中的data
      this.getTreeselect();// 初始化 默认调取部门树状图结构
      // 查询用户详细
      getUser().then(response => {
        console.log("测试查询明细",response);
        this.roleOptions = response.roles;
        this.open = true;
        this.title = "添加用户";
        this.visibleLine = "";
        this.running = "0px 0px";// style
      });
    },

    //新增验证按钮操作
    handVerfi() {
      this.reset();// 把表单重置
      let userIdData=document.getElementById("userIdInput").value;
      getEmpById(userIdData).then(response => {
        console.log("验证",response);
        this.form = response.data[0];
      })
    },

    // 正则
    check_num: function() {
      if(this.forms.empId) {
        this.forms.empId = this.forms.empId.replace(/[^\A-\Z0-9\,]/g, '');
      }
    },

    // 批量添加用户
    handleAddlist() {
      this.resets();// 批量添加表单重置
      getUser().then(response => {
        // 调取用户中的角色
        this.roleOptions = response.roles;
        this.list = true;
        this.title = "批量添加用户";
      });
    },
    // 验证/添加按钮操作
    handAddlist() {
      let userIdAdd=document.getElementById("userIdAddlist").value;
        getEmpById(userIdAdd).then(response => {
          for(var i = 0;i < response.data.length;i++) {
            this.Addlist.push(response.data[i]);
          }
          this.Addlist = this.getsliepAdd();
        })
      this.forms.empId = "";
    },
    getsliepAdd(){
      var resultadd = [];
      var objadd = {};
      for(var i =0; i<this.Addlist.length; i++){
        if(!objadd[this.Addlist[i].empId]){
          resultadd.push(this.Addlist[i]);
          objadd[this.Addlist[i].empId] = true;
        }
      }
      return resultadd;
    },

    // 修改按钮操作
    handleUpdate(row) {
      console.log("修改",row)
      // 左边row中点击出现的都是表格中的一行数据 而上面的修改上面的row出现都是浏览器的数据
      // 重置form
      this.reset();
      // 清空弹出窗体中的Table中的data
      this.getiViret();
      // 初始化,默认调取部门树状图结构
      this.getTreeselect();
      const userId = row.userId || this.ids;
      console.log("测试ids",this.ids);
      console.log("测试userId",row.userId);
      // 详情中修改查询用户详细
      getUser(userId).then(response => {
        // 此处代码是为了读取当前用户的数据
        console.log("测试修改",response);
        this.form = response.data;
        this.roleOptions = response.roles;
        this.form.roleId=response.roleId;
      });
      // 获取当前用户的id的权限
      getDeptPermissionByUser(userId).then(response => {
        // 把这个数据赋值到部门的Table表格中
        this.priviList = response.data;
        this.form.dept= [];
        for(var i = 0;i < response.data.length;i++) {
          // 把数据返回的idPUSH进弹窗中的dep中
          this.form.dept.push(response.data[i].id);
        }
      });
      this.open = true;
      this.title = "修改用户";
      this.visibleLine = "none";
      this.running = "0px 46px";
      this.message = "readonly";
    },

    // 分配角色操作
    handleAuthRole: function(row) {
      const userId = row.userId;
      this.$router.push("/system/user-auth/role/" + userId);
    },
    // 提交按钮
    submitForm: function() {
      this.form.dept=this.dept;
      this.$refs["form"].validate(valid => {
        if(valid) {
            this.form.dept=this.dept;
            // 如果用户的id已经有,就是修改.反之,就是新增.
          if(this.form.userId != undefined) {
            // 修改用户
            updateUser(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          }else {
            this.form.dept=this.dept;
            // 新增用户
            addUser(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    // 批量提交
    submitAddForm: function(){
      for(var i = 0;i < this.Addlist.length;i++){
        this.empIds  += this.Addlist[i].empId + ",";
      }
      this.forms.empIds = this.empIds;
      this.forms.empIds = this.forms.empIds.substring(0,this.forms.empIds.length-1)
        // this.$refs["forms"].validate(valid =>{
        // if(valid){
        addBatch(this.forms).then(response =>{
          this.$modal.msgSuccess("新增成功");
          this.list = false;
          this.getList();
        });
        //   }
        // })
      this.resets();
      this.Addlist = [];
    },

    // 取消按钮
    Addfalse(){
      this.resets();
      this.list = false;
      this.empIds = "";
      this.Addlist = [];
    },

    // 对话框隐藏事件
    handleClose(){
      this.resets();
      this.empIds = "";
      this.Addlist = [];
    },

    // 删除按钮操作
    handleDelete(row) {
      const userIds = row.userId || this.ids;
      this.$modal.confirm('是否确认删除用户编号为"' + userIds + '"的数据项？').then(function() {
        // 删除用户
        return delUser(userIds);
      }).then(() => {
        // 重新调取查询方法
        this.getList();
        // 提示删除成功
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    },

    // 权限表格删除操作
    Deletetable(e) {
      var delist = (e.id);
      for(var i = 0; i < this.priviList.length;i++){
        if(this.priviList[i].id == delist) {
          this.priviList.splice(i,1);
        }
      }
    },
    AddDelete(e){
      var add = (e.empId);
      for(var i = 0;i < this.Addlist.length;i++) {
        if(this.Addlist[i].empId == add) {
          this.Addlist.splice(i,1);
        }
      }
    },

    // 强制渲染
     hangSelectChange() {
      // 因为数据层次太多,render函数没有自动更新,需手动强制刷新.
      this.$forceUpdate();
    },

    // 导出按钮操作
    handleExport() {
      const queryParams = this.queryParams;
      console.log("测试111",this.queryParams);
      this.$modal.confirm('是否确认导出所有用户数据项？').then(() => {
        this.exportLoading = true;
        return exportUser(queryParams);
      }).then(response => {
        this.$download.name(response.msg);
        this.exportLoading = false;
      }).catch(() => {});
    },
    // 导入按钮操作
    handleImport() {
      this.upload.title = "用户导入";
      this.upload.open = true;
    },
    // 下载模板操作
    importTemplate() {
      importTemplate().then(response => {
        this.$download.name(response.msg);
      });
    },
    // 文件上传中处理
    handleFileUploadProgress(event, file, fileList) {
      this.upload.isUploading = true;
    },
    // 文件上传成功处理
    handleFileSuccess(response, file, fileList) {
      this.upload.open = false;
      this.upload.isUploading = false;
      this.$refs.upload.clearFiles();
      this.$alert(response.msg,"导入结果",{dangerouslyUseHTMLString: true});
      this.getList();
    },
    // 提交上传文件
    submitFileForm() {
      this.$refs.upload.submit();
    }
  }
};
</script>
